#include "ServerUIProxy.hpp"
#include <sdbus-c++/IObject.h>

ServerUIProxy::ServerUIProxy()
{}

ServerUIProxy::~ServerUIProxy()
{
  if(workThread.joinable())
  {
    conn->leaveEventLoop();
    workThread.join();
  }
}

void ServerUIProxy::Boot()
{
  conn=sdbus::createSessionBusConnection("org.HBTY.ServerUI");
  object=sdbus::createObject(*conn,"/org/HBTY/ServerUI");
  object->registerSignal("MobileConnect").onInterface(MainInterfaceName).withParameters<bool>();
  object->registerSignal("RecordStatus").onInterface(MainInterfaceName).withParameters<bool>();
  object->finishRegistration();

  workThread=std::thread([this](){
    conn->enterEventLoop();
  });
}

void ServerUIProxy::SetMobileConnectStatus(bool status)
{
  object->emitSignal("MobileConnect").onInterface(MainInterfaceName).withArguments(status);
}

void ServerUIProxy::SetRecordStatus(bool status)
{
  object->emitSignal("RecordStatus").onInterface(MainInterfaceName).withArguments(status);
}

